<!-- 权限管理 -->
<!--
orders
shelves
goodsmanager
tile
space
evaluation
set_goods_call_back_buff
qrcode
coupon
points
coupon
bina
visitorinfo
viplist
sendmail
assshop
storeinfo
setmap
themeimg
mainset
business
invite
permission
-->
<style>
	.permission .perm-item{
		background-color: #002D63;
	    color: #FFF;
	    border-radius: 8px;
	    padding: 0 8px;
	    margin: 1px 2px;
	}
</style>
<div class="permission">
	<div class="nav">
		<div class="nav-li focus">子账号管理</div>
	</div>
	<hr />
	<div class="box">
		<h3>子账号列表</h3>
		<br>
		<table class="paper-table">
			<thead>
				<td>子账号</td>
				<td>密码</td>
				<td>权限</td>
				<td>操作</td>
			</thead>
			{{#each $Cache.bus.permission.bus_child_list}}
			<tr perms="{{perms}}">
				<td style="min-width:4em;text-align:center;">{{name}}</td>
				<td style="min-width:6em;text-align:center;">{{pwd}}</td>
				<td>
					{{#each $Private.titles}}
					<span class="perm-item">{{$This}}</span>
					{{/each}}
				</td>
				<td style="min-width:9em;text-align:center;">
					<button class="icon-pencil" event-click="{{'$Top.$Event.bus.permission.edit_info'}}">编辑信息</button>
					<button class="icon-remove2" event-click="{{'$Top.$Event.bus.permission.remove_employees'}}">删除账号</button>
				</td>
			</tr>
			<script type="text/vm">
function (vm) {
	var trNode = vm.getOneElementByTagName("tr");
	var bus_permission = require("bus_permission");
	jSouper.onElementPropertyChange(trNode, "perms", function(key, value) {
		var titles ;
		if (value) {
			titles = bus_permission.keys_to_titles(value.split(","), App.get("$Cache.perms_tree")/*权限是继承制度的，所以要基于父级的树*/)
		}else{
			titles = []
		}
		vm.set("$Private.titles", titles);
	}, true);
}
			</script>
			{{/each}}
		</table>
		<hr>
		<h3>{{#if $Cache.bus.edit_permission._id}}编辑子账号
		<button event-click="{{'$Event.bus.edit_permission.new'}}">新建子账号</button>{{#else}}新建子账号{{/if}}</h3>
		<br>
		<android:input label="账号名" value="{{$Cache.bus.edit_permission.name}}" bind-input="{{'$Cache.bus.edit_permission.name'}}" description="开头无需书写“{{bus_loginer._id}}:”"></android:input>
		<android:input label="密码" value="{{$Cache.bus.edit_permission.pwd}}" bind-input="{{'$Cache.bus.edit_permission.pwd'}}"></android:input>
		<fieldset>
			<legend>权限控制</legend>
<!-- 			<table class="paper-table">
			<thead>
				<td>业务管理</td>
				<td>营销管理</td>
				<td>商铺管理</td>
			</thead>
			<tr>
				<td style="vertical-align: top;text-align:left;padding-left: 3em;">
					{{#each $Cache.bus.permission.pers_name_map_by_type.业务管理}}
					<android:switch checked="{{#ArrayOwn $Top.$Cache.bus.edit_permission.perms, key}}" bind-input="{{'$Top.$Cache.bus.edit_permission.perms_map.'+key}}" event-change="{{'$Top.$Event.bus.edit_permission.change_perms'}}">{{value}}</android:switch>
					{{/each}}
				</td>
				<td style="vertical-align: top;text-align:left;padding-left: 3em;">
					{{#each $Cache.bus.permission.pers_name_map_by_type.营销管理}}
					<android:switch checked="{{#ArrayOwn $Top.$Cache.bus.edit_permission.perms, key}}" bind-input="{{'$Top.$Cache.bus.edit_permission.perms_map.'+key}}" event-change="{{'$Top.$Event.bus.edit_permission.change_perms'}}">{{value}}</android:switch>
					{{/each}}
				</td>
				<td style="vertical-align: top;text-align:left;padding-left: 3em;">
					{{#each $Cache.bus.permission.pers_name_map_by_type.商铺管理}}
					<android:switch checked="{{#ArrayOwn $Top.$Cache.bus.edit_permission.perms, key}}" bind-input="{{'$Top.$Cache.bus.edit_permission.perms_map.'+key}}" event-change="{{'$Top.$Event.bus.edit_permission.change_perms'}}">{{value}}</android:switch>
					{{/each}}
				</td>
			</tr>
			</table> -->
			<table class="admin-permission-manage paper-table">
				<thead>
				{{#each $Cache.perms_renderable}}
				<td>{{name}}</td>
				{{/each}}
				</thead>
				<tr>
					{{#each $Cache.perms_renderable}}
					<td>
						<div>
						{{#each items}}
							<div>
								<android:array-checkbox source-value="{{childs?window._pers_item_childs_to_keys(childs):[]}}" bind-input="{{'$Top.$Cache.bus.edit_permission.perms'}}" source-checked="{{$Top.$Cache.bus.edit_permission.perms}}">{{title}}</android:array-checkbox>
								<div class="list">
								{{#each childs}}
									<div>
										<android:checkbox checked="{{window._pers_childs_in_keys($Top.$Cache.bus.edit_permission.perms, hash)}}" event-change="{{'$Top.$Event.bus.edit_permission.toggle_checkbox'}}">{{title}}</android:checkbox>
									</div>
								{{/each}}
								</div>
							</div>
						{{/each}}
						</div>
					</td>
					{{/each}}
				</tr>
			</table>
			<style>
	.admin-permission-manage.paper-table tr td{
		vertical-align: top;
		/*text-align: center;*/
	}
	.admin-permission-manage.paper-table tr td .list{
		padding-left: 1.5em;
	}
			</style>
		</fieldset>
		<br>
		<android:paperbutton layer-num=2 event-click="{{'$Event.bus.edit_permission.lock'}}">提交</android:paperbutton>
		<br>
		<br>
	</div>
</div>